#include "test_words.h"
#include <sea_common>

// -------------------------------------------------------------------------------------------------

using namespace sea;

/*
letter
    synonym
        word
            sentence

synonym = { letter | { letter } }  
word = { synonim | { synonim } }
sentence = { word | { word } }

*/

/*

    // Get all words started with 'A'
    VIterator trought 'A' assoiciations
    get object/letter
    get its association
    get association's object which is a list/word
    check if this object/letter is the first in the list/word
    print the word

    // Get all sentences started_from, includes 'aWord'
    VIterator trought 'aWord' assoiciations
    get object/word
    get its association
    get association's object which is a list/sentence
    check if this object/word is the first in the list/sentence
    print the sentence

    // Get contexts started 'aSentence'
    VIterator trought 'aSentence' assoiciations
    get object/sentence
    get its association
    get association's object which is a list/context
    check if this object/sentence is the first in the list/context
    print the context

*/

// const char* stream = "Hello, my name is Vlad! Nice to meet you.";
// const char* stream = "Abba apple an amimal app associations";
// const char* stream = "Hello my friend! How are you? I'm good. You? I'm fine too.";
const char* stream = "Star is bright. Star is lit up by ded moroz. Moon is bright.";

// -------------------------------------------------------------------------------------------------

void test_words( )
{
    if ( 0 )
    {
            // Lets teach this thing to think
            // 1          Word "1" consist of letters "1". Latter is the MEANING. Something undevidable, fundumental, 
            // 1 + 1 = 2. Word "2" consist of letters "11". Latter is the MEANING
            // 2 + 1 = 3. Word "3" consist of letters "21" or "111". Latter is the MEANING
            // 3 + 1 = 4. Word "4" consist of letters "31" or "22" or "211" or "1111". Latter is the MEANING
        {
            const char* one = "1";
            const char* two = "11";
            const char* three = "21";
            const char* four = "31";

            SearchEngine engine;
            engine.add_text( one );
            engine.add_text( two );
            engine.add_text( three );
            engine.add_text( four );

            engine.stats( );
        }
        SEA_MEM_LEAKS( );
    }

    if ( 0 )
    {
        {
            SearchEngine engine;
            engine.add_text( stream );
            engine.stats( );
        }
        SEA_MEM_LEAKS( );
    }

    if ( 0 )
    {
        sea::OsTime timer;
        {
            SearchEngine engine;
            String file( "5.txt" );

            timer.start( );
            engine.add_text( file );
            // engine.add_words( file );

            SEA_TRACE( "Vocabulary created in %d ms", timer.elapsed( ) );

            // Get all words by substr
            char* str = "er";
            vector< String > words = engine.get_all_words_ending( str );
            for ( vector< String >::iterator it = words.begin( ); it != words.end( ); it++ )
            {
                SEA_TRACE( "%s", it->c_str( ) );
            }
            engine.stats( );

            timer.start( );
        }

        SEA_TRACE( "Vocabulary destroyed in %d ms", timer.elapsed( ) );

        SEA_MEM_LEAKS( );
    }

    if ( 1 )
    {
        sea::OsTime timer;
        {
            SearchEngine engine;
            String file( "5.txt" );

            timer.start( );
            engine.add_text( file );

            SEA_TRACE( "Vocabulary created in %d ms", timer.elapsed( ) );

            // engine.stats( );

            timer.start( );
        }

        SEA_TRACE( "Vocabulary destroyed in %d ms", timer.elapsed( ) );

        SEA_MEM_LEAKS( );
    }

}

#if 0
    {
        List* variant1 = create_word( "Hello" );
        List* variant2 = create_word( "Hallo" );
        List* variant3 = create_word( "Helo" );
        List* variant4 = create_word( "Privet" );
        List* variant5 = create_word( "Hi" );

        destroy_alphabet( );

        word2string( variant1 );
        word2string( variant2 );
        word2string( variant3 );
        word2string( variant4 );
        word2string( variant5 );

        ///////////////////
        //List* hello = NEW List( Association( 0, NULL ) );
        List* hello = NEW List;
            /*hello->attach_first( variant1 ); variant1->release_ref( );
            hello->attach_first( variant2 ); variant2->release_ref( );
            hello->attach_first( variant3 ); variant3->release_ref( );
            hello->attach_first( variant4 ); variant4->release_ref( );
            hello->attach_first( variant5 ); variant5->release_ref( );*/

            hello->attach_last( variant1 ); variant1->release_ref( );
            hello->attach_last( variant2 ); variant2->release_ref( );
            hello->attach_last( variant3 ); variant3->release_ref( );
            hello->attach_last( variant4 ); variant4->release_ref( );
            hello->attach_last( variant5 ); variant5->release_ref( );

        hello->release_ref( );
        ///////////////////
        SEA_MEM_LEAKS( );
    }
#endif

// -------------------------------------------------------------------------------------------------
